home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gdb / gdb_18s.zoo / expread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-25  |  56.9 KB  |  2,085 lines

  1.  
  2. /*  A Bison parser, made from expread.y  */
  3.  
  4. #define    INT    258
  5. #define    CHAR    259
  6. #define    FLOAT    260
  7. #define    NAME    261
  8. #define    TYPENAME    262
  9. #define    STRING    263
  10. #define    STRUCT    264
  11. #define    UNION    265
  12. #define    ENUM    266
  13. #define    SIZEOF    267
  14. #define    UNSIGNED    268
  15. #define    COLONCOLON    269
  16. #define    LAST    270
  17. #define    REGNAME    271
  18. #define    VARIABLE    272
  19. #define    ASSIGN_MODIFY    273
  20. #define    ABOVE_COMMA    274
  21. #define    OR    275
  22. #define    AND    276
  23. #define    EQUAL    277
  24. #define    NOTEQUAL    278
  25. #define    LEQ    279
  26. #define    GEQ    280
  27. #define    LSH    281
  28. #define    RSH    282
  29. #define    UNARY    283
  30. #define    INCREMENT    284
  31. #define    DECREMENT    285
  32. #define    ARROW    286
  33.  
  34. #line 30 "expread.y"
  35.  
  36. #include "defs.h"
  37. #include "param.h"
  38. #include "symtab.h"
  39. #include "frame.h"
  40. #include "expression.h"
  41.  
  42. #include <stdio.h>
  43.  
  44. #ifdef atarist
  45. extern int gcc_mshort;
  46. #endif
  47.  
  48. extern CORE_ADDR end_of_text_addr;
  49. static struct expression *expout;
  50. static int expout_size;
  51. static int expout_ptr;
  52.  
  53. static int yylex ();
  54. static yyerror ();
  55. static void write_exp_elt ();
  56. static void write_exp_string ();
  57. static void start_arglist ();
  58. static int end_arglist ();
  59. static void free_funcalls ();
  60. static char *copy_name ();
  61.  
  62. /* If this is nonzero, this block is used as the lexical context
  63.    for symbol names.  */
  64.  
  65. static struct block *expression_context_block;
  66.  
  67. /* Number of arguments seen so far in innermost function call.  */
  68. static int arglist_len;
  69.  
  70. /* Data structure for saving values of arglist_len
  71.    for function calls whose arguments contain other function calls.  */
  72.  
  73. struct funcall
  74.   {
  75.     struct funcall *next;
  76.     int arglist_len;
  77.   };
  78.  
  79. struct funcall *funcall_chain;
  80.  
  81. /* This kind of datum is used to represent the name
  82.    of a symbol token.  */
  83.  
  84. struct stoken
  85.   {
  86.     char *ptr;
  87.     int length;
  88.   };
  89.  
  90. #line 90 "expread.y"
  91. typedef union
  92.   {
  93.     long lval;
  94.     double dval;
  95.     struct symbol *sym;
  96.     struct type *tval;
  97.     struct stoken sval;
  98.     int voidval;
  99.     struct block *bval;
  100.     enum exp_opcode opcode;
  101.     struct internalvar *ivar;
  102.   } YYSTYPE;
  103.  
  104. #ifndef YYLTYPE
  105. typedef
  106.   struct yyltype
  107.     {
  108.       int timestamp;
  109.       int first_line;
  110.       int first_column;
  111.       int last_line;
  112.       int last_column;
  113.       char *text;
  114.    }
  115.   yyltype;
  116.  
  117. #define YYLTYPE yyltype
  118. #endif
  119.  
  120. #include <stdio.h>
  121.  
  122. #ifndef __STDC__
  123. #define const
  124. #endif
  125.  
  126.  
  127.  
  128. #define    YYFINAL        125
  129. #define    YYFLAG        -32768
  130. #define    YYNTBASE    56
  131.  
  132. #define YYTRANSLATE(x) ((unsigned)(x) <= 286 ? yytranslate[x] : 66)
  133.  
  134. static const char yytranslate[] = {     0,
  135.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  136.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  137.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  138.      2,     2,    48,     2,     2,     2,    40,    27,     2,    51,
  139.     52,    38,    36,    19,    37,    46,    39,     2,     2,     2,
  140.      2,     2,     2,     2,     2,     2,     2,    55,     2,    30,
  141.     21,    31,    22,    41,     2,     2,     2,     2,     2,     2,
  142.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  143.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  144.     47,     2,    50,    26,     2,     2,     2,     2,     2,     2,
  145.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  146.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  147.      2,     2,    53,    25,    54,    49,     2,     2,     2,     2,
  148.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  149.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  150.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  151.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  152.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  153.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  154.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  155.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  156.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  157.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  158.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  159.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  160.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  161.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  162.     16,    17,    18,    20,    23,    24,    28,    29,    32,    33,
  163.     34,    35,    42,    43,    44,    45
  164. };
  165.  
  166. static const short yyprhs[] = {     0,
  167.      0,     2,     4,     8,    11,    14,    17,    20,    23,    26,
  168.     29,    32,    35,    38,    42,    46,    51,    52,    58,    59,
  169.     61,    65,    70,    75,    79,    83,    87,    91,    95,    99,
  170.    103,   107,   111,   115,   119,   123,   127,   131,   135,   139,
  171.    143,   147,   151,   155,   161,   165,   169,   171,   173,   175,
  172.    177,   179,   181,   183,   188,   190,   192,   196,   200,   202,
  173.    204,   207,   209,   212,   215,   218,   221,   223
  174. };
  175.  
  176. static const short yyrhs[] = {    57,
  177.      0,    58,     0,    57,    19,    58,     0,    38,    58,     0,
  178.     27,    58,     0,    37,    58,     0,    48,    58,     0,    49,
  179.     58,     0,    43,    58,     0,    44,    58,     0,    58,    43,
  180.      0,    58,    44,     0,    12,    58,     0,    58,    45,    65,
  181.      0,    58,    46,    65,     0,    58,    47,    57,    50,     0,
  182.      0,    58,    51,    59,    60,    52,     0,     0,    58,     0,
  183.     60,    19,    58,     0,    53,    63,    54,    58,     0,    51,
  184.     63,    52,    58,     0,    51,    57,    52,     0,    58,    41,
  185.     58,     0,    58,    38,    58,     0,    58,    39,    58,     0,
  186.     58,    40,    58,     0,    58,    36,    58,     0,    58,    37,
  187.     58,     0,    58,    34,    58,     0,    58,    35,    58,     0,
  188.     58,    28,    58,     0,    58,    29,    58,     0,    58,    32,
  189.     58,     0,    58,    33,    58,     0,    58,    30,    58,     0,
  190.     58,    31,    58,     0,    58,    27,    58,     0,    58,    26,
  191.     58,     0,    58,    25,    58,     0,    58,    24,    58,     0,
  192.     58,    23,    58,     0,    58,    22,    58,    55,    58,     0,
  193.     58,    21,    58,     0,    58,    18,    58,     0,     3,     0,
  194.      4,     0,     5,     0,    62,     0,    15,     0,    16,     0,
  195.     17,     0,    12,    51,    63,    52,     0,     8,     0,    65,
  196.      0,    61,    14,    65,     0,    61,    14,    65,     0,     6,
  197.      0,    64,     0,    63,    38,     0,     7,     0,     9,    65,
  198.      0,    10,    65,     0,    11,    65,     0,    13,    65,     0,
  199.      6,     0,     7,     0
  200. };
  201.  
  202. #if YYDEBUG != 0
  203. static const short yyrline[] = { 0,
  204.    151,   155,   156,   161,   164,   167,   171,   175,   179,   183,
  205.    187,   191,   195,   199,   205,   211,   215,   219,   225,   228,
  206.    232,   236,   242,   248,   254,   258,   262,   266,   270,   274,
  207.    278,   282,   286,   290,   294,   298,   302,   306,   310,   314,
  208.    318,   322,   326,   330,   334,   338,   344,   356,   363,   370,
  209.    373,   379,   385,   391,   398,   404,   423,   432,   443,   487,
  210.    488,   493,   496,   499,   502,   505,   509,   510
  211. };
  212.  
  213. static const char * const yytname[] = {   "$",
  214. "error","$illegal.","INT","CHAR","FLOAT","NAME","TYPENAME","STRING","STRUCT","UNION",
  215. "ENUM","SIZEOF","UNSIGNED","COLONCOLON","LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","','","ABOVE_COMMA",
  216. "'='","'?'","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'",
  217. "'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'",
  218. "'@'","UNARY","INCREMENT","DECREMENT","ARROW","'.'","'['","'!'","'~'","']'",
  219. "'('","')'","'{'","'}'","':'","start","exp1","exp","@1","arglist",
  220. "block","variable","type","typebase","name",""
  221. };
  222. #endif
  223.  
  224. static const short yyr1[] = {     0,
  225.     56,    57,    57,    58,    58,    58,    58,    58,    58,    58,
  226.     58,    58,    58,    58,    58,    58,    59,    58,    60,    60,
  227.     60,    58,    58,    58,    58,    58,    58,    58,    58,    58,
  228.     58,    58,    58,    58,    58,    58,    58,    58,    58,    58,
  229.     58,    58,    58,    58,    58,    58,    58,    58,    58,    58,
  230.     58,    58,    58,    58,    58,    61,    61,    62,    62,    63,
  231.     63,    64,    64,    64,    64,    64,    65,    65
  232. };
  233.  
  234. static const short yyr2[] = {     0,
  235.      1,     1,     3,     2,     2,     2,     2,     2,     2,     2,
  236.      2,     2,     2,     3,     3,     4,     0,     5,     0,     1,
  237.      3,     4,     4,     3,     3,     3,     3,     3,     3,     3,
  238.      3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
  239.      3,     3,     3,     5,     3,     3,     1,     1,     1,     1,
  240.      1,     1,     1,     4,     1,     1,     3,     3,     1,     1,
  241.      2,     1,     2,     2,     2,     2,     1,     1
  242. };
  243.  
  244. static const short yydefact[] = {     0,
  245.     47,    48,    49,    59,    68,    55,     0,    51,    52,    53,
  246.      0,     0,     0,     0,     0,     0,     0,     0,     0,     1,
  247.      2,     0,    50,    56,     0,    13,     5,     6,     4,     9,
  248.     10,     7,     8,    62,     0,     0,     0,     0,     0,     0,
  249.     60,    62,     0,     0,     0,     0,     0,     0,     0,     0,
  250.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  251.      0,     0,     0,     0,     0,     0,    11,    12,     0,     0,
  252.      0,    17,     0,     0,    67,    63,    64,    65,    66,    24,
  253.     61,     0,     0,     3,    46,    45,     0,    43,    42,    41,
  254.     40,    39,    33,    34,    37,    38,    35,    36,    31,    32,
  255.     29,    30,    26,    27,    28,    25,    14,    15,     0,    19,
  256.     58,    54,    23,    22,     0,    16,    20,     0,    44,     0,
  257.     18,    21,     0,     0,     0
  258. };
  259.  
  260. static const short yydefgoto[] = {   123,
  261.     39,    21,   110,   118,    22,    23,    40,    41,    24
  262. };
  263.  
  264. static const short yypact[] = {   125,
  265. -32768,-32768,-32768,     4,-32768,-32768,   143,-32768,-32768,-32768,
  266.    125,   125,   125,   125,   125,   125,   125,    74,     6,    11,
  267.    217,    50,-32768,-32768,    74,   456,   456,   456,   456,   456,
  268.    456,   456,   456,    53,    67,    67,    67,    67,   -17,   -26,
  269. -32768,-32768,   -27,   125,   125,   125,   125,   125,   125,   125,
  270.    125,   125,   125,   125,   125,   125,   125,   125,   125,   125,
  271.    125,   125,   125,   125,   125,   125,-32768,-32768,    67,    67,
  272.    125,-32768,    67,   -24,-32768,-32768,-32768,-32768,-32768,-32768,
  273. -32768,   125,   125,   217,   217,   217,   182,   275,   302,   328,
  274.    353,   377,   399,   399,   417,   417,   417,   417,   433,   433,
  275.    447,   447,    51,    51,    51,   456,-32768,-32768,    12,   125,
  276.     57,    17,   456,   456,   125,-32768,   217,   -16,   247,   125,
  277. -32768,   217,    88,    93,-32768
  278. };
  279.  
  280. static const short yypgoto[] = {-32768,
  281.      1,    -7,-32768,-32768,-32768,-32768,    44,-32768,   129
  282. };
  283.  
  284.  
  285. #define    YYLAST        507
  286.  
  287.  
  288. static const short yytable[] = {    26,
  289.     20,    44,   120,    27,    28,    29,    30,    31,    32,    33,
  290.     81,    81,    42,    81,    35,    36,    37,   -67,    38,     1,
  291.      2,     3,     4,     5,     6,    82,    83,   112,     7,    44,
  292.     44,     8,     9,    10,    80,   121,    84,    85,    86,    87,
  293.     88,    89,    90,    91,    92,    93,    94,    95,    96,    97,
  294.     98,    99,   100,   101,   102,   103,   104,   105,   106,    14,
  295.     15,   116,    43,    73,    16,    17,   -68,    18,    74,    19,
  296.    -57,   109,    75,     5,   113,   114,     1,     2,     3,     4,
  297.     34,     6,    35,    36,    37,     7,    38,   124,     8,     9,
  298.     10,    66,   125,    67,    68,    69,    70,    71,     0,     0,
  299.     11,    72,   117,     0,   113,     0,     0,   119,     0,     0,
  300.     12,    13,   122,     0,     0,     0,    14,    15,     0,     0,
  301.      0,    16,    17,     0,    18,     0,    19,     1,     2,     3,
  302.      4,     5,     6,     0,     0,     0,     7,     0,     0,     8,
  303.      9,    10,     0,     0,     0,     1,     2,     3,     4,     5,
  304.      6,    11,     0,     0,     7,     0,     0,     8,     9,    10,
  305.      0,    12,    13,    76,    77,    78,    79,    14,    15,    11,
  306.      0,     0,    16,    17,     0,    18,     0,    19,     0,    12,
  307.     13,     0,     0,     0,     0,    14,    15,     0,     0,     0,
  308.     16,    17,     0,    25,     0,    19,     0,   107,   108,    45,
  309.      0,   111,    46,    47,    48,    49,    50,    51,    52,    53,
  310.     54,    55,    56,    57,    58,    59,    60,    61,    62,    63,
  311.     64,    65,    66,     0,    67,    68,    69,    70,    71,     0,
  312.      0,     0,    72,     0,    45,     0,   115,    46,    47,    48,
  313.     49,    50,    51,    52,    53,    54,    55,    56,    57,    58,
  314.     59,    60,    61,    62,    63,    64,    65,    66,     0,    67,
  315.     68,    69,    70,    71,     0,     0,     0,    72,    47,    48,
  316.     49,    50,    51,    52,    53,    54,    55,    56,    57,    58,
  317.     59,    60,    61,    62,    63,    64,    65,    66,     0,    67,
  318.     68,    69,    70,    71,     0,     0,     0,    72,    49,    50,
  319.     51,    52,    53,    54,    55,    56,    57,    58,    59,    60,
  320.     61,    62,    63,    64,    65,    66,     0,    67,    68,    69,
  321.     70,    71,     0,     0,     0,    72,    50,    51,    52,    53,
  322.     54,    55,    56,    57,    58,    59,    60,    61,    62,    63,
  323.     64,    65,    66,     0,    67,    68,    69,    70,    71,     0,
  324.      0,     0,    72,    51,    52,    53,    54,    55,    56,    57,
  325.     58,    59,    60,    61,    62,    63,    64,    65,    66,     0,
  326.     67,    68,    69,    70,    71,     0,     0,     0,    72,    52,
  327.     53,    54,    55,    56,    57,    58,    59,    60,    61,    62,
  328.     63,    64,    65,    66,     0,    67,    68,    69,    70,    71,
  329.      0,     0,     0,    72,    53,    54,    55,    56,    57,    58,
  330.     59,    60,    61,    62,    63,    64,    65,    66,     0,    67,
  331.     68,    69,    70,    71,     0,     0,     0,    72,    55,    56,
  332.     57,    58,    59,    60,    61,    62,    63,    64,    65,    66,
  333.      0,    67,    68,    69,    70,    71,     0,     0,     0,    72,
  334.     59,    60,    61,    62,    63,    64,    65,    66,     0,    67,
  335.     68,    69,    70,    71,     0,     0,     0,    72,    61,    62,
  336.     63,    64,    65,    66,     0,    67,    68,    69,    70,    71,
  337.      0,     0,     0,    72,    63,    64,    65,    66,     0,    67,
  338.     68,    69,    70,    71,     0,     0,     0,    72,    67,    68,
  339.     69,    70,    71,     0,     0,     0,    72
  340. };
  341.  
  342. static const short yycheck[] = {     7,
  343.      0,    19,    19,    11,    12,    13,    14,    15,    16,    17,
  344.     38,    38,     7,    38,     9,    10,    11,    14,    13,     3,
  345.      4,     5,     6,     7,     8,    52,    54,    52,    12,    19,
  346.     19,    15,    16,    17,    52,    52,    44,    45,    46,    47,
  347.     48,    49,    50,    51,    52,    53,    54,    55,    56,    57,
  348.     58,    59,    60,    61,    62,    63,    64,    65,    66,    43,
  349.     44,    50,    19,    14,    48,    49,    14,    51,    25,    53,
  350.     14,    71,     6,     7,    82,    83,     3,     4,     5,     6,
  351.      7,     8,     9,    10,    11,    12,    13,     0,    15,    16,
  352.     17,    41,     0,    43,    44,    45,    46,    47,    -1,    -1,
  353.     27,    51,   110,    -1,   112,    -1,    -1,   115,    -1,    -1,
  354.     37,    38,   120,    -1,    -1,    -1,    43,    44,    -1,    -1,
  355.     -1,    48,    49,    -1,    51,    -1,    53,     3,     4,     5,
  356.      6,     7,     8,    -1,    -1,    -1,    12,    -1,    -1,    15,
  357.     16,    17,    -1,    -1,    -1,     3,     4,     5,     6,     7,
  358.      8,    27,    -1,    -1,    12,    -1,    -1,    15,    16,    17,
  359.     -1,    37,    38,    35,    36,    37,    38,    43,    44,    27,
  360.     -1,    -1,    48,    49,    -1,    51,    -1,    53,    -1,    37,
  361.     38,    -1,    -1,    -1,    -1,    43,    44,    -1,    -1,    -1,
  362.     48,    49,    -1,    51,    -1,    53,    -1,    69,    70,    18,
  363.     -1,    73,    21,    22,    23,    24,    25,    26,    27,    28,
  364.     29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
  365.     39,    40,    41,    -1,    43,    44,    45,    46,    47,    -1,
  366.     -1,    -1,    51,    -1,    18,    -1,    55,    21,    22,    23,
  367.     24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
  368.     34,    35,    36,    37,    38,    39,    40,    41,    -1,    43,
  369.     44,    45,    46,    47,    -1,    -1,    -1,    51,    22,    23,
  370.     24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
  371.     34,    35,    36,    37,    38,    39,    40,    41,    -1,    43,
  372.     44,    45,    46,    47,    -1,    -1,    -1,    51,    24,    25,
  373.     26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
  374.     36,    37,    38,    39,    40,    41,    -1,    43,    44,    45,
  375.     46,    47,    -1,    -1,    -1,    51,    25,    26,    27,    28,
  376.     29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
  377.     39,    40,    41,    -1,    43,    44,    45,    46,    47,    -1,
  378.     -1,    -1,    51,    26,    27,    28,    29,    30,    31,    32,
  379.     33,    34,    35,    36,    37,    38,    39,    40,    41,    -1,
  380.     43,    44,    45,    46,    47,    -1,    -1,    -1,    51,    27,
  381.     28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
  382.     38,    39,    40,    41,    -1,    43,    44,    45,    46,    47,
  383.     -1,    -1,    -1,    51,    28,    29,    30,    31,    32,    33,
  384.     34,    35,    36,    37,    38,    39,    40,    41,    -1,    43,
  385.     44,    45,    46,    47,    -1,    -1,    -1,    51,    30,    31,
  386.     32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
  387.     -1,    43,    44,    45,    46,    47,    -1,    -1,    -1,    51,
  388.     34,    35,    36,    37,    38,    39,    40,    41,    -1,    43,
  389.     44,    45,    46,    47,    -1,    -1,    -1,    51,    36,    37,
  390.     38,    39,    40,    41,    -1,    43,    44,    45,    46,    47,
  391.     -1,    -1,    -1,    51,    38,    39,    40,    41,    -1,    43,
  392.     44,    45,    46,    47,    -1,    -1,    -1,    51,    43,    44,
  393.     45,    46,    47,    -1,    -1,    -1,    51
  394. };
  395. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  396. #line 3 "/net/acae127/home/bammi/lib/bison.simple"
  397.  
  398. /* Skeleton output parser for bison,
  399.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  400.  
  401.    This program is free software; you can redistribute it and/or modify
  402.    it under the terms of the GNU General Public License as published by
  403.    the Free Software Foundation; either version 1, or (at your option)
  404.    any later version.
  405.  
  406.    This program is distributed in the hope that it will be useful,
  407.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  408.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  409.    GNU General Public License for more details.
  410.  
  411.    You should have received a copy of the GNU General Public License
  412.    along with this program; if not, write to the Free Software
  413.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  414.  
  415.  
  416. #ifndef alloca
  417. #ifdef __GNUC__
  418. #define alloca __builtin_alloca
  419. #else /* Not GNU C.  */
  420. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  421. #include <alloca.h>
  422. #else /* Not sparc */
  423. #ifdef MSDOS
  424. #include <malloc.h>
  425. #endif /* MSDOS */
  426. #endif /* Not sparc.  */
  427. #endif /* Not GNU C.  */
  428. #endif /* alloca not defined.  */
  429.  
  430. /* This is the parser code that is written into each bison parser
  431.   when the %semantic_parser declaration is not specified in the grammar.
  432.   It was written by Richard Stallman by simplifying the hairy parser
  433.   used when %semantic_parser is specified.  */
  434.  
  435. /* Note: there must be only one dollar sign in this file.
  436.    It is replaced by the list of actions, each action
  437.    as one case of the switch.  */
  438.  
  439. #define yyerrok        (yyerrstatus = 0)
  440. #define yyclearin    (yychar = YYEMPTY)
  441. #define YYEMPTY        -2
  442. #define YYEOF        0
  443. #define YYACCEPT    return(0)
  444. #define YYABORT     return(1)
  445. #define YYERROR        goto yyerrlab1
  446. /* Like YYERROR except do call yyerror.
  447.    This remains here temporarily to ease the
  448.    transition to the new meaning of YYERROR, for GCC.
  449.    Once GCC version 2 has supplanted version 1, this can go.  */
  450. #define YYFAIL        goto yyerrlab
  451. #define YYRECOVERING()  (!!yyerrstatus)
  452. #define YYBACKUP(token, value) \
  453. do                                \
  454.   if (yychar == YYEMPTY && yylen == 1)                \
  455.     { yychar = (token), yylval = (value);            \
  456.       yychar1 = YYTRANSLATE (yychar);                \
  457.       YYPOPSTACK;                        \
  458.       goto yybackup;                        \
  459.     }                                \
  460.   else                                \
  461.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  462. while (0)
  463.  
  464. #define YYTERROR    1
  465. #define YYERRCODE    256
  466.  
  467. #ifndef YYPURE
  468. #define YYLEX        yylex()
  469. #endif
  470.  
  471. #ifdef YYPURE
  472. #ifdef YYLSP_NEEDED
  473. #define YYLEX        yylex(&yylval, &yylloc)
  474. #else
  475. #define YYLEX        yylex(&yylval)
  476. #endif
  477. #endif
  478.  
  479. /* If nonreentrant, generate the variables here */
  480.  
  481. #ifndef YYPURE
  482.  
  483. int    yychar;            /*  the lookahead symbol        */
  484. YYSTYPE    yylval;            /*  the semantic value of the        */
  485.                 /*  lookahead symbol            */
  486.  
  487. #ifdef YYLSP_NEEDED
  488. YYLTYPE yylloc;            /*  location data for the lookahead    */
  489.                 /*  symbol                */
  490. #endif
  491.  
  492. int yynerrs;            /*  number of parse errors so far       */
  493. #endif  /* not YYPURE */
  494.  
  495. #if YYDEBUG != 0
  496. int yydebug;            /*  nonzero means print parse trace    */
  497. /* Since this is uninitialized, it does not stop multiple parsers
  498.    from coexisting.  */
  499. #endif
  500.  
  501. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  502.  
  503. #ifndef    YYINITDEPTH
  504. #define YYINITDEPTH 200
  505. #endif
  506.  
  507. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  508.     (effective only if the built-in stack extension method is used).  */
  509.  
  510. #if YYMAXDEPTH == 0
  511. #undef YYMAXDEPTH
  512. #endif
  513.  
  514. #ifndef YYMAXDEPTH
  515. #define YYMAXDEPTH 10000
  516. #endif
  517.  
  518. #ifndef __cplusplus
  519.  
  520. /* This is the most reliable way to avoid incompatibilities
  521.    in available built-in functions on various systems.  */
  522. static void
  523. __yy_bcopy (from, to, count)
  524.      char *from;
  525.      char *to;
  526.      int count;
  527. {
  528.   register char *f = from;
  529.   register char *t = to;
  530.   register int i = count;
  531.  
  532.   while (i-- > 0)
  533.     *t++ = *f++;
  534. }
  535.  
  536. #else /* __cplusplus */
  537.  
  538. /* This is the most reliable way to avoid incompatibilities
  539.    in available built-in functions on various systems.  */
  540. static void
  541. __yy_bcopy (char *from, char *to, int count)
  542. {
  543.   register char *f = from;
  544.   register char *t = to;
  545.   register int i = count;
  546.  
  547.   while (i-- > 0)
  548.     *t++ = *f++;
  549. }
  550.  
  551. #endif
  552.  
  553. #line 160 "/net/acae127/home/bammi/lib/bison.simple"
  554. int
  555. yyparse()
  556. {
  557.   register int yystate;
  558.   register int yyn;
  559.   register short *yyssp;
  560.   register YYSTYPE *yyvsp;
  561.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  562.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  563.  
  564.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  565.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  566.  
  567.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  568.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  569.  
  570. #ifdef YYLSP_NEEDED
  571.   YYLTYPE *yyls = yylsa;
  572.   YYLTYPE *yylsp;
  573.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  574.  
  575. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  576. #else
  577. #define YYPOPSTACK   (yyvsp--, yysp--)
  578. #endif
  579.  
  580.   int yystacksize = YYINITDEPTH;
  581.  
  582. #ifdef YYPURE
  583.   int yychar;
  584.   YYSTYPE yylval;
  585.   int yynerrs;
  586. #ifdef YYLSP_NEEDED
  587.   YYLTYPE yylloc;
  588. #endif
  589. #endif
  590.  
  591.   YYSTYPE yyval;        /*  the variable used to return        */
  592.                 /*  semantic values from the action    */
  593.                 /*  routines                */
  594.  
  595.   int yylen;
  596.  
  597. #if YYDEBUG != 0
  598.   if (yydebug)
  599.     fprintf(stderr, "Starting parse\n");
  600. #endif
  601.  
  602.   yystate = 0;
  603.   yyerrstatus = 0;
  604.   yynerrs = 0;
  605.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  606.  
  607.   /* Initialize stack pointers.
  608.      Waste one element of value and location stack
  609.      so that they stay on the same level as the state stack.  */
  610.  
  611.   yyssp = yyss - 1;
  612.   yyvsp = yyvs;
  613. #ifdef YYLSP_NEEDED
  614.   yylsp = yyls;
  615. #endif
  616.  
  617. /* Push a new state, which is found in  yystate  .  */
  618. /* In all cases, when you get here, the value and location stacks
  619.    have just been pushed. so pushing a state here evens the stacks.  */
  620. yynewstate:
  621.  
  622.   *++yyssp = yystate;
  623.  
  624.   if (yyssp >= yyss + yystacksize - 1)
  625.     {
  626.       /* Give user a chance to reallocate the stack */
  627.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  628.       YYSTYPE *yyvs1 = yyvs;
  629.       short *yyss1 = yyss;
  630. #ifdef YYLSP_NEEDED
  631.       YYLTYPE *yyls1 = yyls;
  632. #endif
  633.  
  634.       /* Get the current used size of the three stacks, in elements.  */
  635.       int size = yyssp - yyss + 1;
  636.  
  637. #ifdef yyoverflow
  638.       /* Each stack pointer address is followed by the size of
  639.      the data in use in that stack, in bytes.  */
  640.       yyoverflow("parser stack overflow",
  641.          &yyss1, size * sizeof (*yyssp),
  642.          &yyvs1, size * sizeof (*yyvsp),
  643. #ifdef YYLSP_NEEDED
  644.          &yyls1, size * sizeof (*yylsp),
  645. #endif
  646.          &yystacksize);
  647.  
  648.       yyss = yyss1; yyvs = yyvs1;
  649. #ifdef YYLSP_NEEDED
  650.       yyls = yyls1;
  651. #endif
  652. #else /* no yyoverflow */
  653.       /* Extend the stack our own way.  */
  654.       if (yystacksize >= YYMAXDEPTH)
  655.     {
  656.       yyerror("parser stack overflow");
  657.       return 2;
  658.     }
  659.       yystacksize *= 2;
  660.       if (yystacksize > YYMAXDEPTH)
  661.     yystacksize = YYMAXDEPTH;
  662.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  663.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  664.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  665.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  666. #ifdef YYLSP_NEEDED
  667.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  668.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  669. #endif
  670. #endif /* no yyoverflow */
  671.  
  672.       yyssp = yyss + size - 1;
  673.       yyvsp = yyvs + size - 1;
  674. #ifdef YYLSP_NEEDED
  675.       yylsp = yyls + size - 1;
  676. #endif
  677.  
  678. #if YYDEBUG != 0
  679.       if (yydebug)
  680.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  681. #endif
  682.  
  683.       if (yyssp >= yyss + yystacksize - 1)
  684.     YYABORT;
  685.     }
  686.  
  687. #if YYDEBUG != 0
  688.   if (yydebug)
  689.     fprintf(stderr, "Entering state %d\n", yystate);
  690. #endif
  691.  
  692.  yybackup:
  693.  
  694. /* Do appropriate processing given the current state.  */
  695. /* Read a lookahead token if we need one and don't already have one.  */
  696. /* yyresume: */
  697.  
  698.   /* First try to decide what to do without reference to lookahead token.  */
  699.  
  700.   yyn = yypact[yystate];
  701.   if (yyn == YYFLAG)
  702.     goto yydefault;
  703.  
  704.   /* Not known => get a lookahead token if don't already have one.  */
  705.  
  706.   /* yychar is either YYEMPTY or YYEOF
  707.      or a valid token in external form.  */
  708.  
  709.   if (yychar == YYEMPTY)
  710.     {
  711. #if YYDEBUG != 0
  712.       if (yydebug)
  713.     fprintf(stderr, "Reading a token: ");
  714. #endif
  715.       yychar = YYLEX;
  716.     }
  717.  
  718.   /* Convert token to internal form (in yychar1) for indexing tables with */
  719.  
  720.   if (yychar <= 0)        /* This means end of input. */
  721.     {
  722.       yychar1 = 0;
  723.       yychar = YYEOF;        /* Don't call YYLEX any more */
  724.  
  725. #if YYDEBUG != 0
  726.       if (yydebug)
  727.     fprintf(stderr, "Now at end of input.\n");
  728. #endif
  729.     }
  730.   else
  731.     {
  732.       yychar1 = YYTRANSLATE(yychar);
  733.  
  734. #if YYDEBUG != 0
  735.       if (yydebug)
  736.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  737. #endif
  738.     }
  739.  
  740.   yyn += yychar1;
  741.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  742.     goto yydefault;
  743.  
  744.   yyn = yytable[yyn];
  745.  
  746.   /* yyn is what to do for this token type in this state.
  747.      Negative => reduce, -yyn is rule number.
  748.      Positive => shift, yyn is new state.
  749.        New state is final state => don't bother to shift,
  750.        just return success.
  751.      0, or most negative number => error.  */
  752.  
  753.   if (yyn < 0)
  754.     {
  755.       if (yyn == YYFLAG)
  756.     goto yyerrlab;
  757.       yyn = -yyn;
  758.       goto yyreduce;
  759.     }
  760.   else if (yyn == 0)
  761.     goto yyerrlab;
  762.  
  763.   if (yyn == YYFINAL)
  764.     YYACCEPT;
  765.  
  766.   /* Shift the lookahead token.  */
  767.  
  768. #if YYDEBUG != 0
  769.   if (yydebug)
  770.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  771. #endif
  772.  
  773.   /* Discard the token being shifted unless it is eof.  */
  774.   if (yychar != YYEOF)
  775.     yychar = YYEMPTY;
  776.  
  777.   *++yyvsp = yylval;
  778. #ifdef YYLSP_NEEDED
  779.   *++yylsp = yylloc;
  780. #endif
  781.  
  782.   /* count tokens shifted since error; after three, turn off error status.  */
  783.   if (yyerrstatus) yyerrstatus--;
  784.  
  785.   yystate = yyn;
  786.   goto yynewstate;
  787.  
  788. /* Do the default action for the current state.  */
  789. yydefault:
  790.  
  791.   yyn = yydefact[yystate];
  792.   if (yyn == 0)
  793.     goto yyerrlab;
  794.  
  795. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  796. yyreduce:
  797.   yylen = yyr2[yyn];
  798.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  799.  
  800. #if YYDEBUG != 0
  801.   if (yydebug)
  802.     {
  803.       int i;
  804.  
  805.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  806.            yyn, yyrline[yyn]);
  807.  
  808.       /* Print the symboles being reduced, and their result.  */
  809.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  810.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  811.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  812.     }
  813. #endif
  814.  
  815.  
  816.   switch (yyn) {
  817.  
  818. case 3:
  819. #line 157 "expread.y"
  820. { write_exp_elt (BINOP_COMMA); ;
  821.     break;}
  822. case 4:
  823. #line 162 "expread.y"
  824. { write_exp_elt (UNOP_IND); ;
  825.     break;}
  826. case 5:
  827. #line 165 "expread.y"
  828. { write_exp_elt (UNOP_ADDR); ;
  829.     break;}
  830. case 6:
  831. #line 168 "expread.y"
  832. { write_exp_elt (UNOP_NEG); ;
  833.     break;}
  834. case 7:
  835. #line 172 "expread.y"
  836. { write_exp_elt (UNOP_ZEROP); ;
  837.     break;}
  838. case 8:
  839. #line 176 "expread.y"
  840. { write_exp_elt (UNOP_LOGNOT); ;
  841.     break;}
  842. case 9:
  843. #line 180 "expread.y"
  844. { write_exp_elt (UNOP_PREINCREMENT); ;
  845.     break;}
  846. case 10:
  847. #line 184 "expread.y"
  848. { write_exp_elt (UNOP_PREDECREMENT); ;
  849.     break;}
  850. case 11:
  851. #line 188 "expread.y"
  852. { write_exp_elt (UNOP_POSTINCREMENT); ;
  853.     break;}
  854. case 12:
  855. #line 192 "expread.y"
  856. { write_exp_elt (UNOP_POSTDECREMENT); ;
  857.     break;}
  858. case 13:
  859. #line 196 "expread.y"
  860. { write_exp_elt (UNOP_SIZEOF); ;
  861.     break;}
  862. case 14:
  863. #line 200 "expread.y"
  864. { write_exp_elt (STRUCTOP_PTR);
  865.               write_exp_string (yyvsp[0].sval);
  866.               write_exp_elt (STRUCTOP_PTR); ;
  867.     break;}
  868. case 15:
  869. #line 206 "expread.y"
  870. { write_exp_elt (STRUCTOP_STRUCT);
  871.               write_exp_string (yyvsp[0].sval);
  872.               write_exp_elt (STRUCTOP_STRUCT); ;
  873.     break;}
  874. case 16:
  875. #line 212 "expread.y"
  876. { write_exp_elt (BINOP_SUBSCRIPT); ;
  877.     break;}
  878. case 17:
  879. #line 218 "expread.y"
  880. { start_arglist (); ;
  881.     break;}
  882. case 18:
  883. #line 220 "expread.y"
  884. { write_exp_elt (OP_FUNCALL);
  885.               write_exp_elt (end_arglist ());
  886.               write_exp_elt (OP_FUNCALL); ;
  887.     break;}
  888. case 20:
  889. #line 229 "expread.y"
  890. { arglist_len = 1; ;
  891.     break;}
  892. case 21:
  893. #line 233 "expread.y"
  894. { arglist_len++; ;
  895.     break;}
  896. case 22:
  897. #line 237 "expread.y"
  898. { write_exp_elt (UNOP_MEMVAL);
  899.               write_exp_elt (yyvsp[-2].tval);
  900.               write_exp_elt (UNOP_MEMVAL); ;
  901.     break;}
  902. case 23:
  903. #line 243 "expread.y"
  904. { write_exp_elt (UNOP_CAST);
  905.               write_exp_elt (yyvsp[-2].tval);
  906.               write_exp_elt (UNOP_CAST); ;
  907.     break;}
  908. case 24:
  909. #line 249 "expread.y"
  910. { ;
  911.     break;}
  912. case 25:
  913. #line 255 "expread.y"
  914. { write_exp_elt (BINOP_REPEAT); ;
  915.     break;}
  916. case 26:
  917. #line 259 "expread.y"
  918. { write_exp_elt (BINOP_MUL); ;
  919.     break;}
  920. case 27:
  921. #line 263 "expread.y"
  922. { write_exp_elt (BINOP_DIV); ;
  923.     break;}
  924. case 28:
  925. #line 267 "expread.y"
  926. { write_exp_elt (BINOP_REM); ;
  927.     break;}
  928. case 29:
  929. #line 271 "expread.y"
  930. { write_exp_elt (BINOP_ADD); ;
  931.     break;}
  932. case 30:
  933. #line 275 "expread.y"
  934. { write_exp_elt (BINOP_SUB); ;
  935.     break;}
  936. case 31:
  937. #line 279 "expread.y"
  938. { write_exp_elt (BINOP_LSH); ;
  939.     break;}
  940. case 32:
  941. #line 283 "expread.y"
  942. { write_exp_elt (BINOP_RSH); ;
  943.     break;}
  944. case 33:
  945. #line 287 "expread.y"
  946. { write_exp_elt (BINOP_EQUAL); ;
  947.     break;}
  948. case 34:
  949. #line 291 "expread.y"
  950. { write_exp_elt (BINOP_NOTEQUAL); ;
  951.     break;}
  952. case 35:
  953. #line 295 "expread.y"
  954. { write_exp_elt (BINOP_LEQ); ;
  955.     break;}
  956. case 36:
  957. #line 299 "expread.y"
  958. { write_exp_elt (BINOP_GEQ); ;
  959.     break;}
  960. case 37:
  961. #line 303 "expread.y"
  962. { write_exp_elt (BINOP_LESS); ;
  963.     break;}
  964. case 38:
  965. #line 307 "expread.y"
  966. { write_exp_elt (BINOP_GTR); ;
  967.     break;}
  968. case 39:
  969. #line 311 "expread.y"
  970. { write_exp_elt (BINOP_LOGAND); ;
  971.     break;}
  972. case 40:
  973. #line 315 "expread.y"
  974. { write_exp_elt (BINOP_LOGXOR); ;
  975.     break;}
  976. case 41:
  977. #line 319 "expread.y"
  978. { write_exp_elt (BINOP_LOGIOR); ;
  979.     break;}
  980. case 42:
  981. #line 323 "expread.y"
  982. { write_exp_elt (BINOP_AND); ;
  983.     break;}
  984. case 43:
  985. #line 327 "expread.y"
  986. { write_exp_elt (BINOP_OR); ;
  987.     break;}
  988. case 44:
  989. #line 331 "expread.y"
  990. { write_exp_elt (TERNOP_COND); ;
  991.     break;}
  992. case 45:
  993. #line 335 "expread.y"
  994. { write_exp_elt (BINOP_ASSIGN); ;
  995.     break;}
  996. case 46:
  997. #line 339 "expread.y"
  998. { write_exp_elt (BINOP_ASSIGN_MODIFY);
  999.               write_exp_elt (yyvsp[-1].opcode);
  1000.               write_exp_elt (BINOP_ASSIGN_MODIFY); ;
  1001.     break;}
  1002. case 47:
  1003. #line 345 "expread.y"
  1004. { write_exp_elt (OP_LONG);
  1005. #if 0
  1006.               if(gcc_mshort)
  1007.                   write_exp_elt (builtin_type_short);
  1008.               else
  1009. #endif
  1010.               write_exp_elt (builtin_type_int);
  1011.               write_exp_elt (yyvsp[0].lval);
  1012.               write_exp_elt (OP_LONG); ;
  1013.     break;}
  1014. case 48:
  1015. #line 357 "expread.y"
  1016. { write_exp_elt (OP_LONG);
  1017.               write_exp_elt (builtin_type_char);
  1018.               write_exp_elt (yyvsp[0].lval);
  1019.               write_exp_elt (OP_LONG); ;
  1020.     break;}
  1021. case 49:
  1022. #line 364 "expread.y"
  1023. { write_exp_elt (OP_DOUBLE);
  1024.               write_exp_elt (builtin_type_double);
  1025.               write_exp_elt (yyvsp[0].dval);
  1026.               write_exp_elt (OP_DOUBLE); ;
  1027.     break;}
  1028. case 51:
  1029. #line 374 "expread.y"
  1030. { write_exp_elt (OP_LAST);
  1031.               write_exp_elt (yyvsp[0].lval);
  1032.               write_exp_elt (OP_LAST); ;
  1033.     break;}
  1034. case 52:
  1035. #line 380 "expread.y"
  1036. { write_exp_elt (OP_REGISTER);
  1037.               write_exp_elt (yyvsp[0].lval);
  1038.               write_exp_elt (OP_REGISTER); ;
  1039.     break;}
  1040. case 53:
  1041. #line 386 "expread.y"
  1042. { write_exp_elt (OP_INTERNALVAR);
  1043.               write_exp_elt (yyvsp[0].ivar);
  1044.               write_exp_elt (OP_INTERNALVAR); ;
  1045.     break;}
  1046. case 54:
  1047. #line 392 "expread.y"
  1048. { write_exp_elt (OP_LONG);
  1049.               write_exp_elt (builtin_type_long);
  1050.               write_exp_elt ((long) TYPE_LENGTH (yyvsp[-1].tval));
  1051.               write_exp_elt (OP_LONG); ;
  1052.     break;}
  1053. case 55:
  1054. #line 399 "expread.y"
  1055. { write_exp_elt (OP_STRING);
  1056.               write_exp_string (yyvsp[0].sval);
  1057.               write_exp_elt (OP_STRING); ;
  1058.     break;}
  1059. case 56:
  1060. #line 405 "expread.y"
  1061. { struct symtab *tem = lookup_symtab (copy_name (yyvsp[0].sval));
  1062.               struct symbol *sym;
  1063.               
  1064.               if (tem)
  1065.                 yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
  1066.               else
  1067.                 {
  1068.                   sym = lookup_symbol (copy_name (yyvsp[0].sval),
  1069.                            expression_context_block,
  1070.                            VAR_NAMESPACE);
  1071.                   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  1072.                 yyval.bval = SYMBOL_BLOCK_VALUE (sym);
  1073.                   else
  1074.                 error ("No file or function \"%s\".",
  1075.                        copy_name (yyvsp[0].sval));
  1076.                 };
  1077.     break;}
  1078. case 57:
  1079. #line 424 "expread.y"
  1080. { struct symbol *tem
  1081.                 = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE);
  1082.               if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  1083.                 error ("No function \"%s\" in specified context.",
  1084.                    copy_name (yyvsp[0].sval));
  1085.               yyval.bval = SYMBOL_BLOCK_VALUE (tem); ;
  1086.     break;}
  1087. case 58:
  1088. #line 433 "expread.y"
  1089. { struct symbol *sym;
  1090.               sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE);
  1091.               if (sym == 0)
  1092.                 error ("No symbol \"%s\" in specified context.",
  1093.                    copy_name (yyvsp[0].sval));
  1094.               write_exp_elt (OP_VAR_VALUE);
  1095.               write_exp_elt (sym);
  1096.               write_exp_elt (OP_VAR_VALUE); ;
  1097.     break;}
  1098. case 59:
  1099. #line 444 "expread.y"
  1100. { struct symbol *sym;
  1101.               sym = lookup_symbol (copy_name (yyvsp[0].sval),
  1102.                           expression_context_block,
  1103.                           VAR_NAMESPACE);
  1104.               if (sym)
  1105.                 {
  1106.                   write_exp_elt (OP_VAR_VALUE);
  1107.                   write_exp_elt (sym);
  1108.                   write_exp_elt (OP_VAR_VALUE);
  1109.                 }
  1110.               else
  1111.                 {
  1112.                   register char *arg = copy_name (yyvsp[0].sval);
  1113.                   register int i;
  1114.                   for (i = 0; i < misc_function_count; i++)
  1115.                 if (!strcmp (misc_function_vector[i].name, arg))
  1116.                   break;
  1117.  
  1118.                   if (i < misc_function_count)
  1119.                 {
  1120.                   write_exp_elt (OP_LONG);
  1121.                   write_exp_elt (builtin_type_int);
  1122.                   write_exp_elt (misc_function_vector[i].address);
  1123.                   write_exp_elt (OP_LONG);
  1124.                   write_exp_elt (UNOP_MEMVAL);
  1125. /*                  write_exp_elt (builtin_type_char); */
  1126.                       if(misc_function_vector[i].address <= end_of_text_addr)
  1127.                       write_exp_elt
  1128.                           (lookup_function_type(builtin_type_int));
  1129.                   else
  1130.                       write_exp_elt(builtin_type_int);
  1131.                   write_exp_elt (UNOP_MEMVAL);
  1132.                 }
  1133.                   else
  1134.                 if (symtab_list == 0)
  1135.                   error ("No symbol table is loaded.  Use the \"symbol-file\" command.");
  1136.                 else
  1137.                   error ("No symbol \"%s\" in current context.",
  1138.                      copy_name (yyvsp[0].sval));
  1139.                 }
  1140.             ;
  1141.     break;}
  1142. case 61:
  1143. #line 489 "expread.y"
  1144. { yyval.tval = lookup_pointer_type (yyvsp[-1].tval); ;
  1145.     break;}
  1146. case 62:
  1147. #line 494 "expread.y"
  1148. { yyval.tval = lookup_typename (copy_name (yyvsp[0].sval),
  1149.                         expression_context_block, 0); ;
  1150.     break;}
  1151. case 63:
  1152. #line 497 "expread.y"
  1153. { yyval.tval = lookup_struct (copy_name (yyvsp[0].sval),
  1154.                           expression_context_block); ;
  1155.     break;}
  1156. case 64:
  1157. #line 500 "expread.y"
  1158. { yyval.tval = lookup_union (copy_name (yyvsp[0].sval),
  1159.                          expression_context_block); ;
  1160.     break;}
  1161. case 65:
  1162. #line 503 "expread.y"
  1163. { yyval.tval = lookup_enum (copy_name (yyvsp[0].sval),
  1164.                         expression_context_block); ;
  1165.     break;}
  1166. case 66:
  1167. #line 506 "expread.y"
  1168. { yyval.tval = lookup_unsigned_typename (copy_name (yyvsp[0].sval)); ;
  1169.     break;}
  1170. }
  1171.    /* the action file gets copied in in place of this dollarsign */
  1172. #line 423 "/net/acae127/home/bammi/lib/bison.simple"
  1173.  
  1174.   yyvsp -= yylen;
  1175.   yyssp -= yylen;
  1176. #ifdef YYLSP_NEEDED
  1177.   yylsp -= yylen;
  1178. #endif
  1179.  
  1180. #if YYDEBUG != 0
  1181.   if (yydebug)
  1182.     {
  1183.       short *ssp1 = yyss - 1;
  1184.       fprintf (stderr, "state stack now");
  1185.       while (ssp1 != yyssp)
  1186.     fprintf (stderr, " %d", *++ssp1);
  1187.       fprintf (stderr, "\n");
  1188.     }
  1189. #endif
  1190.  
  1191.   *++yyvsp = yyval;
  1192.  
  1193. #ifdef YYLSP_NEEDED
  1194.   yylsp++;
  1195.   if (yylen == 0)
  1196.     {
  1197.       yylsp->first_line = yylloc.first_line;
  1198.       yylsp->first_column = yylloc.first_column;
  1199.       yylsp->last_line = (yylsp-1)->last_line;
  1200.       yylsp->last_column = (yylsp-1)->last_column;
  1201.       yylsp->text = 0;
  1202.     }
  1203.   else
  1204.     {
  1205.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1206.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1207.     }
  1208. #endif
  1209.  
  1210.   /* Now "shift" the result of the reduction.
  1211.      Determine what state that goes to,
  1212.      based on the state we popped back to
  1213.      and the rule number reduced by.  */
  1214.  
  1215.   yyn = yyr1[yyn];
  1216.  
  1217.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1218.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1219.     yystate = yytable[yystate];
  1220.   else
  1221.     yystate = yydefgoto[yyn - YYNTBASE];
  1222.  
  1223.   goto yynewstate;
  1224.  
  1225. yyerrlab:   /* here on detecting error */
  1226.  
  1227.   if (! yyerrstatus)
  1228.     /* If not already recovering from an error, report this error.  */
  1229.     {
  1230.       ++yynerrs;
  1231.  
  1232. #ifdef YYERROR_VERBOSE
  1233.       yyn = yypact[yystate];
  1234.  
  1235.       if (yyn > YYFLAG && yyn < YYLAST)
  1236.     {
  1237.       int size = 0;
  1238.       char *msg;
  1239.       int x, count;
  1240.  
  1241.       count = 0;
  1242.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1243.         if (yycheck[x + yyn] == x)
  1244.           size += strlen(yytname[x]) + 15, count++;
  1245.       msg = (char *) xmalloc(size + 15);
  1246.       strcpy(msg, "parse error");
  1247.  
  1248.       if (count < 5)
  1249.         {
  1250.           count = 0;
  1251.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1252.         if (yycheck[x + yyn] == x)
  1253.           {
  1254.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1255.             strcat(msg, yytname[x]);
  1256.             strcat(msg, "'");
  1257.             count++;
  1258.           }
  1259.         }
  1260.       yyerror(msg);
  1261.       free(msg);
  1262.     }
  1263.       else
  1264. #endif /* YYERROR_VERBOSE */
  1265.     yyerror("parse error");
  1266.     }
  1267.  
  1268. yyerrlab1:   /* here on error raised explicitly by an action */
  1269.  
  1270.   if (yyerrstatus == 3)
  1271.     {
  1272.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1273.  
  1274.       /* return failure if at end of input */
  1275.       if (yychar == YYEOF)
  1276.     YYABORT;
  1277.  
  1278. #if YYDEBUG != 0
  1279.       if (yydebug)
  1280.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1281. #endif
  1282.  
  1283.       yychar = YYEMPTY;
  1284.     }
  1285.  
  1286.   /* Else will try to reuse lookahead token
  1287.      after shifting the error token.  */
  1288.  
  1289.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1290.  
  1291.   goto yyerrhandle;
  1292.  
  1293. yyerrdefault:  /* current state does not do anything special for the error token. */
  1294.  
  1295. #if 0
  1296.   /* This is wrong; only states that explicitly want error tokens
  1297.      should shift them.  */
  1298.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1299.   if (yyn) goto yydefault;
  1300. #endif
  1301.  
  1302. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1303.  
  1304.   if (yyssp == yyss) YYABORT;
  1305.   yyvsp--;
  1306.   yystate = *--yyssp;
  1307. #ifdef YYLSP_NEEDED
  1308.   yylsp--;
  1309. #endif
  1310.  
  1311. #if YYDEBUG != 0
  1312.   if (yydebug)
  1313.     {
  1314.       short *ssp1 = yyss - 1;
  1315.       fprintf (stderr, "Error: state stack now");
  1316.       while (ssp1 != yyssp)
  1317.     fprintf (stderr, " %d", *++ssp1);
  1318.       fprintf (stderr, "\n");
  1319.     }
  1320. #endif
  1321.  
  1322. yyerrhandle:
  1323.  
  1324.   yyn = yypact[yystate];
  1325.   if (yyn == YYFLAG)
  1326.     goto yyerrdefault;
  1327.  
  1328.   yyn += YYTERROR;
  1329.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1330.     goto yyerrdefault;
  1331.  
  1332.   yyn = yytable[yyn];
  1333.   if (yyn < 0)
  1334.     {
  1335.       if (yyn == YYFLAG)
  1336.     goto yyerrpop;
  1337.       yyn = -yyn;
  1338.       goto yyreduce;
  1339.     }
  1340.   else if (yyn == 0)
  1341.     goto yyerrpop;
  1342.  
  1343.   if (yyn == YYFINAL)
  1344.     YYACCEPT;
  1345.  
  1346. #if YYDEBUG != 0
  1347.   if (yydebug)
  1348.     fprintf(stderr, "Shifting error token, ");
  1349. #endif
  1350.  
  1351.   *++yyvsp = yylval;
  1352. #ifdef YYLSP_NEEDED
  1353.   *++yylsp = yylloc;
  1354. #endif
  1355.  
  1356.   yystate = yyn;
  1357.   goto yynewstate;
  1358. }
  1359. #line 512 "expread.y"
  1360.  
  1361.  
  1362. /* Begin counting arguments for a function call,
  1363.    saving the data about any containing call.  */
  1364.  
  1365. static void
  1366. start_arglist ()
  1367. {
  1368.   register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
  1369.  
  1370.   new->next = funcall_chain;
  1371.   new->arglist_len = arglist_len;
  1372.   arglist_len = 0;
  1373.   funcall_chain = new;
  1374. }
  1375.  
  1376. /* Return the number of arguments in a function call just terminated,
  1377.    and restore the data for the containing function call.  */
  1378.  
  1379. static int
  1380. end_arglist ()
  1381. {
  1382.   register int val = arglist_len;
  1383.   register struct funcall *call = funcall_chain;
  1384.   funcall_chain = call->next;
  1385.   arglist_len = call->arglist_len;
  1386.   free (call);
  1387.   return val;
  1388. }
  1389.  
  1390. /* Free everything in the funcall chain.
  1391.    Used when there is an error inside parsing.  */
  1392.  
  1393. static void
  1394. free_funcalls ()
  1395. {
  1396.   register struct funcall *call, *next;
  1397.  
  1398.   for (call = funcall_chain; call; call = next)
  1399.     {
  1400.       next = call->next;
  1401.       free (call);
  1402.     }
  1403. }
  1404.  
  1405. /* This page contains the functions for adding data to the  struct expression
  1406.    being constructed.  */
  1407.  
  1408. /* Add one element to the end of the expression.  */
  1409.  
  1410. static void
  1411. write_exp_elt (expelt)
  1412.      union exp_element expelt;
  1413. {
  1414.   if (expout_ptr >= expout_size)
  1415.     {
  1416.       expout_size *= 2;
  1417.       expout = (struct expression *) xrealloc (expout,
  1418.                            sizeof (struct expression)
  1419.                            + expout_size * sizeof (union exp_element));
  1420.     }
  1421.   expout->elts[expout_ptr++] = expelt;
  1422. }
  1423.  
  1424. /* Add a string constant to the end of the expression.
  1425.    Follow it by its length in bytes, as a separate exp_element.  */
  1426.  
  1427. static void
  1428. write_exp_string (str)
  1429.      struct stoken str;
  1430. {
  1431.   register int len = str.length;
  1432.   register int lenelt
  1433.     = (len + sizeof (union exp_element)) / sizeof (union exp_element);
  1434.  
  1435.   expout_ptr += lenelt;
  1436.  
  1437.   if (expout_ptr >= expout_size)
  1438.     {
  1439.       expout_size = max (expout_size * 2, expout_ptr + 10);
  1440.       expout = (struct expression *) xrealloc (expout,
  1441.                            sizeof (struct expression)
  1442.                            + expout_size * sizeof (union exp_element));
  1443.     }
  1444.   bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
  1445.   ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
  1446.   write_exp_elt (len);
  1447. }
  1448.  
  1449. /* During parsing of a C expression, the pointer to the next character
  1450.    is in this variable.  */
  1451.  
  1452. static char *lexptr;
  1453.  
  1454. /* Tokens that refer to names do so with explicit pointer and length,
  1455.    so they can share the storage that lexptr is parsing.
  1456.  
  1457.    When it is necessary to pass a name to a function that expects
  1458.    a null-terminated string, the substring is copied out
  1459.    into a block of storage that namecopy points to.
  1460.  
  1461.    namecopy is allocated once, guaranteed big enough, for each parsing.  */
  1462.  
  1463. static char *namecopy;
  1464.  
  1465. /* Current depth in parentheses within the expression.  */
  1466.  
  1467. static int paren_depth;
  1468.  
  1469. /* Nonzero means stop parsing on first comma (if not within parentheses).  */
  1470.  
  1471. static int comma_terminates;
  1472.  
  1473. /* Take care of parsing a number (anything that starts with a digit).
  1474.    Set yylval and return the token type; update lexptr.
  1475.    LEN is the number of characters in it.  */
  1476.  
  1477. /*** Needs some error checking for the float case ***/
  1478.  
  1479. static int
  1480. parse_number (olen)
  1481.      int olen;
  1482. {
  1483.   register char *p = lexptr;
  1484.   register long n = 0;
  1485.   register int c;
  1486.   register int base = 10;
  1487.   register int len = olen;
  1488.   char *err_copy;
  1489.  
  1490.   extern double atof ();
  1491.  
  1492.   for (c = 0; c < len; c++)
  1493.     if (p[c] == '.')
  1494.       {
  1495.     /* It's a float since it contains a point.  */
  1496.     yylval.dval = atof (p);
  1497.     lexptr += len;
  1498.     return FLOAT;
  1499.       }
  1500.  
  1501.   if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2)))
  1502.     {
  1503.       p += 2;
  1504.       base = 16;
  1505.       len -= 2;
  1506.     }
  1507.   else if (*p == '0')
  1508.     base = 8;
  1509.  
  1510.   while (len-- > 0)
  1511.     {
  1512.       c = *p++;
  1513.       n *= base;
  1514.       if (c >= '0' && c <= '9')
  1515.     n += c - '0';
  1516.       else
  1517.     {
  1518.       if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
  1519.       if (base == 16 && c >= 'a' && c <= 'f')
  1520.         n += c - 'a' + 10;
  1521.       else if (len == 0 && c == 'l')
  1522.         ;
  1523.       else
  1524.         {
  1525.           err_copy = (char *) alloca (olen + 1);
  1526.           bcopy (lexptr, err_copy, olen);
  1527.           err_copy[olen] = 0;
  1528.           error ("Invalid number \"%s\".", err_copy);
  1529.         }
  1530.     }
  1531.     }
  1532.  
  1533.   lexptr = p;
  1534.   yylval.lval = n;
  1535.   return INT;
  1536. }
  1537.  
  1538. struct token
  1539. {
  1540.   char *operator;
  1541.   int token;
  1542.   enum exp_opcode opcode;
  1543. };
  1544.  
  1545. static struct token tokentab3[] =
  1546.   {
  1547.     {">>=", ASSIGN_MODIFY, BINOP_RSH},
  1548.     {"<<=", ASSIGN_MODIFY, BINOP_LSH}
  1549.   };
  1550.  
  1551. static struct token tokentab2[] =
  1552.   {
  1553.     {"+=", ASSIGN_MODIFY, BINOP_ADD},
  1554.     {"-=", ASSIGN_MODIFY, BINOP_SUB},
  1555.     {"*=", ASSIGN_MODIFY, BINOP_MUL},
  1556.     {"/=", ASSIGN_MODIFY, BINOP_DIV},
  1557.     {"%=", ASSIGN_MODIFY, BINOP_REM},
  1558.     {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
  1559.     {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
  1560.     {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
  1561.     {"++", INCREMENT, BINOP_END},
  1562.     {"--", DECREMENT, BINOP_END},
  1563.     {"->", ARROW, BINOP_END},
  1564.     {"&&", AND, BINOP_END},
  1565.     {"||", OR, BINOP_END},
  1566.     {"::", COLONCOLON, BINOP_END},
  1567.     {"<<", LSH, BINOP_END},
  1568.     {">>", RSH, BINOP_END},
  1569.     {"==", EQUAL, BINOP_END},
  1570.     {"!=", NOTEQUAL, BINOP_END},
  1571.     {"<=", LEQ, BINOP_END},
  1572.     {">=", GEQ, BINOP_END}
  1573.   };
  1574.  
  1575. /* Read one token, getting characters through lexptr.  */
  1576.  
  1577. static int
  1578. yylex ()
  1579. {
  1580.   register int c;
  1581.   register int namelen;
  1582.   register int i;
  1583.   register char *tokstart;
  1584.  
  1585.  retry:
  1586.  
  1587.   tokstart = lexptr;
  1588.   /* See if it is a special token of length 3.  */
  1589.   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1590.     if (!strncmp (tokstart, tokentab3[i].operator, 3))
  1591.       {
  1592.     lexptr += 3;
  1593.     yylval.opcode = tokentab3[i].opcode;
  1594.     return tokentab3[i].token;
  1595.       }
  1596.  
  1597.   /* See if it is a special token of length 2.  */
  1598.   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1599.     if (!strncmp (tokstart, tokentab2[i].operator, 2))
  1600.       {
  1601.     lexptr += 2;
  1602.     yylval.opcode = tokentab2[i].opcode;
  1603.     return tokentab2[i].token;
  1604.       }
  1605.  
  1606.   switch (c = *tokstart)
  1607.     {
  1608.     case 0:
  1609.       return 0;
  1610.  
  1611.     case ' ':
  1612.     case '\t':
  1613.     case '\n':
  1614.       lexptr++;
  1615.       goto retry;
  1616.  
  1617.     case '\'':
  1618.       lexptr++;
  1619.       c = *lexptr++;
  1620.       if (c == '\\')
  1621.     c = parse_escape (&lexptr);
  1622.       yylval.lval = c;
  1623.       c = *lexptr++;
  1624.       if (c != '\'')
  1625.     error ("Invalid character constant.");
  1626.       return CHAR;
  1627.  
  1628.     case '(':
  1629.       paren_depth++;
  1630.       lexptr++;
  1631.       return c;
  1632.  
  1633.     case ')':
  1634.       if (paren_depth == 0)
  1635.     return 0;
  1636.       paren_depth--;
  1637.       lexptr++;
  1638.       return c;
  1639.  
  1640.     case ',':
  1641.       if (comma_terminates && paren_depth == 0)
  1642.     return 0;
  1643.       lexptr++;
  1644.       return c;
  1645.  
  1646.     case '+':
  1647.     case '-':
  1648.     case '*':
  1649.     case '/':
  1650.     case '%':
  1651.     case '|':
  1652.     case '&':
  1653.     case '^':
  1654.     case '~':
  1655.     case '!':
  1656.     case '@':
  1657.     case '<':
  1658.     case '>':
  1659.     case '[':
  1660.     case ']':
  1661.     case '.':
  1662.     case '?':
  1663.     case ':':
  1664.     case '=':
  1665.     case '{':
  1666.     case '}':
  1667.       lexptr++;
  1668.       return c;
  1669.  
  1670.     case '"':
  1671.       for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
  1672.     if (c == '\\')
  1673.       {
  1674.         c = tokstart[++namelen];
  1675.         if (c >= '0' && c <= '9')
  1676.           {
  1677.         c = tokstart[++namelen];
  1678.         if (c >= '0' && c <= '9')
  1679.           c = tokstart[++namelen];
  1680.           }
  1681.       }
  1682.       yylval.sval.ptr = tokstart + 1;
  1683.       yylval.sval.length = namelen - 1;
  1684.       lexptr += namelen + 1;
  1685.       return STRING;
  1686.     }
  1687.   if (c >= '0' && c <= '9')
  1688.     {
  1689.       /* It's a number */
  1690.       for (namelen = 0;
  1691.        c = tokstart[namelen],
  1692.        (c == '_' || c == '$' || c == '.' || (c >= '0' && c <= '9')
  1693.         || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
  1694.        namelen++)
  1695.     ;
  1696.       return parse_number (namelen);
  1697.     }
  1698.  
  1699.   if (!(c == '_' || c == '$'
  1700.     || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
  1701.     error ("Invalid token in expression.");
  1702.  
  1703.   /* It is a name.  See how long it is.  */
  1704.  
  1705.   for (namelen = 0;
  1706.        c = tokstart[namelen],
  1707.        (c == '_' || c == '$' || (c >= '0' && c <= '9')
  1708.     || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
  1709.        namelen++)
  1710.     ;
  1711.  
  1712.   /* The token "if" terminates the expression and is NOT 
  1713.      removed from the input stream.  */
  1714.   if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
  1715.     {
  1716.       return 0;
  1717.     }
  1718.  
  1719.   lexptr += namelen;
  1720.  
  1721.   /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
  1722.      and $$digits (equivalent to $<-digits> if you could type that).
  1723.      Make token type LAST, and put the number (the digits) in yylval.  */
  1724.  
  1725.   if (*tokstart == '$')
  1726.     {
  1727.       register int negate = 0;
  1728.       c = 1;
  1729.       /* Double dollar means negate the number and add -1 as well.
  1730.      Thus $$ alone means -1.  */
  1731.       if (namelen >= 2 && tokstart[1] == '$')
  1732.     {
  1733.       negate = 1;
  1734.       c = 2;
  1735.     }
  1736.       if (c == namelen)
  1737.     {
  1738.       /* Just dollars (one or two) */
  1739.       yylval.lval = - negate;
  1740.       return LAST;
  1741.     }
  1742.       /* Is the rest of the token digits?  */
  1743.       for (; c < namelen; c++)
  1744.     if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
  1745.       break;
  1746.       if (c == namelen)
  1747.     {
  1748.       yylval.lval = atoi (tokstart + 1 + negate);
  1749.       if (negate)
  1750.         yylval.lval = - yylval.lval;
  1751.       return LAST;
  1752.     }
  1753.     }
  1754.  
  1755.   /* Handle tokens that refer to machine registers:
  1756.      $ followed by a register name.  */
  1757.  
  1758.   if (*tokstart == '$')
  1759.     for (c = 0; c < NUM_REGS; c++)
  1760.       if (namelen - 1 == strlen (reg_names[c])
  1761.       && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
  1762.     {
  1763.       yylval.lval = c;
  1764.       return REGNAME;
  1765.     }
  1766.  
  1767.   if (namelen == 6 && !strncmp (tokstart, "struct", 6))
  1768.     {
  1769.       return STRUCT;
  1770.     }
  1771.   if (namelen == 5 && !strncmp (tokstart, "union", 5))
  1772.     {
  1773.       return UNION;
  1774.     }
  1775.   if (namelen == 4 && !strncmp (tokstart, "enum", 4))
  1776.     {
  1777.       return ENUM;
  1778.     }
  1779.   if (namelen == 6 && !strncmp (tokstart, "sizeof", 6))
  1780.     {
  1781.       return SIZEOF;
  1782.     }
  1783.   if (namelen == 8 && !strncmp (tokstart, "unsigned", 6))
  1784.     {
  1785.       return UNSIGNED;
  1786.     }
  1787.   yylval.sval.ptr = tokstart;
  1788.   yylval.sval.length = namelen;
  1789.  
  1790.   /* Any other names starting in $ are debugger internal variables.  */
  1791.  
  1792.   if (*tokstart == '$')
  1793.     {
  1794.       yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
  1795.       return VARIABLE;
  1796.     }
  1797.  
  1798.   /* Use token-type TYPENAME for symbols that happen to be defined
  1799.      currently as names of types; NAME for other symbols.
  1800.      The caller is not constrained to care about the distinction.  */
  1801.   if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
  1802.     return TYPENAME;
  1803.   return NAME;
  1804. }
  1805.  
  1806. static
  1807. yyerror ()
  1808. {
  1809.   error ("Invalid syntax in expression.");
  1810. }
  1811.  
  1812. /* Return a null-terminated temporary copy of the name
  1813.    of a string token.  */
  1814.  
  1815. static char *
  1816. copy_name (token)
  1817.      struct stoken token;
  1818. {
  1819.   bcopy (token.ptr, namecopy, token.length);
  1820.   namecopy[token.length] = 0;
  1821.   return namecopy;
  1822. }
  1823.  
  1824. /* Reverse an expression from suffix form (in which it is constructed)
  1825.    to prefix form (in which we can conveniently print or execute it).  */
  1826.  
  1827. static void prefixify_subexp ();
  1828.  
  1829. static void
  1830. prefixify_expression (expr)
  1831.      register struct expression *expr;
  1832. {
  1833.   register int len = sizeof (struct expression) +
  1834.                     expr->nelts * sizeof (union exp_element);
  1835.   register struct expression *temp;
  1836.   register int inpos = expr->nelts, outpos = 0;
  1837.  
  1838.   temp = (struct expression *) alloca (len);
  1839.  
  1840.   /* Copy the original expression into temp.  */
  1841.   bcopy (expr, temp, len);
  1842.  
  1843.   prefixify_subexp (temp, expr, inpos, outpos);
  1844. }
  1845.  
  1846. /* Return the number of exp_elements in the subexpression of EXPR
  1847.    whose last exp_element is at index ENDPOS - 1 in EXPR.  */
  1848.  
  1849. static int
  1850. length_of_subexp (expr, endpos)
  1851.      register struct expression *expr;
  1852.      register int endpos;
  1853. {
  1854.   register int oplen = 1;
  1855.   register int args = 0;
  1856.   register int i;
  1857.  
  1858.   if (endpos < 0)
  1859.     error ("?error in length_of_subexp");
  1860.  
  1861.   i = (int) expr->elts[endpos - 1].opcode;
  1862.  
  1863.   switch (i)
  1864.     {
  1865.     case OP_LONG:
  1866.     case OP_DOUBLE:
  1867.       oplen = 4;
  1868.       break;
  1869.  
  1870.     case OP_VAR_VALUE:
  1871.     case OP_LAST:
  1872.     case OP_REGISTER:
  1873.     case OP_INTERNALVAR:
  1874.       oplen = 3;
  1875.       break;
  1876.  
  1877.     case OP_FUNCALL:
  1878.       oplen = 3;
  1879.       args = 1 + expr->elts[endpos - 2].longconst;
  1880.       break;
  1881.  
  1882.     case UNOP_CAST:
  1883.     case UNOP_MEMVAL:
  1884.       oplen = 3;
  1885.       args = 1;
  1886.       break;
  1887.  
  1888.     case STRUCTOP_STRUCT:
  1889.     case STRUCTOP_PTR:
  1890.       args = 1;
  1891.     case OP_STRING:
  1892.       oplen = 3 + ((expr->elts[endpos - 2].longconst
  1893.             + sizeof (union exp_element))
  1894.            / sizeof (union exp_element));
  1895.            
  1896.       break;
  1897.  
  1898.     case TERNOP_COND:
  1899.       args = 3;
  1900.       break;
  1901.  
  1902.     case BINOP_ASSIGN_MODIFY:
  1903.       oplen = 3;
  1904.       args = 2;
  1905.       break;
  1906.  
  1907.     default:
  1908.       args = 1 + (i < (int) BINOP_END);
  1909.     }
  1910.  
  1911.   while (args > 0)
  1912.     {
  1913.       oplen += length_of_subexp (expr, endpos - oplen);
  1914.       args--;
  1915.     }
  1916.  
  1917.   return oplen;
  1918. }
  1919.  
  1920. /* Copy the subexpression ending just before index INEND in INEXPR
  1921.    into OUTEXPR, starting at index OUTBEG.
  1922.    In the process, convert it from suffix to prefix form.  */
  1923.  
  1924. static void
  1925. prefixify_subexp (inexpr, outexpr, inend, outbeg)
  1926.      register struct expression *inexpr;
  1927.      struct expression *outexpr;
  1928.      register int inend;
  1929.      int outbeg;
  1930. {
  1931.   register int oplen = 1;
  1932.   register int args = 0;
  1933.   register int i;
  1934.   int *arglens;
  1935.   enum exp_opcode opcode;
  1936.  
  1937.   /* Compute how long the last operation is (in OPLEN),
  1938.      and also how many preceding subexpressions serve as
  1939.      arguments for it (in ARGS).  */
  1940.  
  1941.   opcode = inexpr->elts[inend - 1].opcode;
  1942.   switch (opcode)
  1943.     {
  1944.     case OP_LONG:
  1945.     case OP_DOUBLE:
  1946.       oplen = 4;
  1947.       break;
  1948.  
  1949.     case OP_VAR_VALUE:
  1950.     case OP_LAST:
  1951.     case OP_REGISTER:
  1952.     case OP_INTERNALVAR:
  1953.       oplen = 3;
  1954.       break;
  1955.  
  1956.     case OP_FUNCALL:
  1957.       oplen = 3;
  1958.       args = 1 + inexpr->elts[inend - 2].longconst;
  1959.       break;
  1960.  
  1961.     case UNOP_CAST:
  1962.     case UNOP_MEMVAL:
  1963.       oplen = 3;
  1964.       args = 1;
  1965.       break;
  1966.  
  1967.     case STRUCTOP_STRUCT:
  1968.     case STRUCTOP_PTR:
  1969.       args = 1;
  1970.     case OP_STRING:
  1971.       oplen = 3 + ((inexpr->elts[inend - 2].longconst
  1972.             + sizeof (union exp_element))
  1973.            / sizeof (union exp_element));
  1974.            
  1975.       break;
  1976.  
  1977.     case TERNOP_COND:
  1978.       args = 3;
  1979.       break;
  1980.  
  1981.     case BINOP_ASSIGN_MODIFY:
  1982.       oplen = 3;
  1983.       args = 2;
  1984.       break;
  1985.  
  1986.     default:
  1987.       args = 1 + ((int) opcode < (int) BINOP_END);
  1988.     }
  1989.  
  1990.   /* Copy the final operator itself, from the end of the input
  1991.      to the beginning of the output.  */
  1992.   inend -= oplen;
  1993.   bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
  1994.      oplen * sizeof (union exp_element));
  1995.   outbeg += oplen;
  1996.  
  1997.   /* Find the lengths of the arg subexpressions.  */
  1998.   arglens = (int *) alloca (args * sizeof (int));
  1999.   for (i = args - 1; i >= 0; i--)
  2000.     {
  2001.       oplen = length_of_subexp (inexpr, inend);
  2002.       arglens[i] = oplen;
  2003.       inend -= oplen;
  2004.     }
  2005.  
  2006.   /* Now copy each subexpression, preserving the order of
  2007.      the subexpressions, but prefixifying each one.
  2008.      In this loop, inend starts at the beginning of
  2009.      the expression this level is working on
  2010.      and marches forward over the arguments.
  2011.      outbeg does similarly in the output.  */
  2012.   for (i = 0; i < args; i++)
  2013.     {
  2014.       oplen = arglens[i];
  2015.       inend += oplen;
  2016.       prefixify_subexp (inexpr, outexpr, inend, outbeg);
  2017.       outbeg += oplen;
  2018.     }
  2019. }
  2020.  
  2021. /* This page contains the two entry points to this file.  */
  2022.  
  2023. /* Read a C expression from the string *STRINGPTR points to,
  2024.    parse it, and return a pointer to a  struct expression  that we malloc.
  2025.    Use block BLOCK as the lexical context for variable names;
  2026.    if BLOCK is zero, use the block of the selected stack frame.
  2027.    Meanwhile, advance *STRINGPTR to point after the expression,
  2028.    at the first nonwhite character that is not part of the expression
  2029.    (possibly a null character).
  2030.  
  2031.    If COMMA is nonzero, stop if a comma is reached.  */
  2032.  
  2033. struct expression *
  2034. parse_c_1 (stringptr, block, comma)
  2035.      char **stringptr;
  2036.      struct block *block;
  2037. {
  2038.   struct cleanup *old_chain;
  2039.  
  2040.   lexptr = *stringptr;
  2041.  
  2042.   paren_depth = 0;
  2043.   comma_terminates = comma;
  2044.  
  2045.   if (lexptr == 0 || *lexptr == 0)
  2046.     error_no_arg ("expression to compute");
  2047.  
  2048.   old_chain = make_cleanup (free_funcalls, 0);
  2049.   funcall_chain = 0;
  2050.  
  2051.   expression_context_block = block ? block : get_selected_block ();
  2052.  
  2053.   namecopy = (char *) alloca (strlen (lexptr) + 1);
  2054.   expout_size = 10;
  2055.   expout_ptr = 0;
  2056.   expout = (struct expression *) xmalloc (sizeof (struct expression)
  2057.                       + expout_size * sizeof (union exp_element));
  2058.   make_cleanup (free_current_contents, &expout);
  2059.   if (yyparse ())
  2060.     yyerror ();
  2061.   discard_cleanups (old_chain);
  2062.   expout->nelts = expout_ptr;
  2063.   expout = (struct expression *)
  2064.     xrealloc (expout,
  2065.           sizeof (struct expression)
  2066.           + expout_ptr * sizeof (union exp_element));
  2067.   prefixify_expression (expout);
  2068.   *stringptr = lexptr;
  2069.   return expout;
  2070. }
  2071.  
  2072. /* Parse STRING as an expression, and complain if this fails
  2073.    to use up all of the contents of STRING.  */
  2074.  
  2075. struct expression *
  2076. parse_c_expression (string)
  2077.      char *string;
  2078. {
  2079.   register struct expression *exp;
  2080.   exp = parse_c_1 (&string, 0, 0);
  2081.   if (*string)
  2082.     error ("Junk after end of expression.");
  2083.   return exp;
  2084. }
  2085.